# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=nose
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.3.7
pkgrel=3
pkgdesc="A discovery-based unittest extension (mingw-w64)"
arch=('any')
license=('LGPL-2.1')
url="https://nose.readthedocs.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
source=("https://pypi.python.org/packages/source/n/nose/nose-${pkgver}.tar.gz")
sha256sums=('f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98')

build() {
  cd "${srcdir}/nose-${pkgver}"
  sed -i -e "s:man/man1:share/man/man1:g" setup.py

  cd "${srcdir}"
  rm -rf python{2,3}-build
  for builddir in python{2,3}-build; do
    cp -r nose-${pkgver} $builddir
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

package_python3-nose() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})

  cd "${srcdir}/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  rm -f ${pkgdir}${MINGW_PREFIX}/bin/nosetests{.exe,-script.py,.exe.manifest}
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${_mingw_prefix}/bin/|/usr/bin/env |g" -i ${_f}
  done
  rm -rf "${pkgdir}${MINGW_PREFIX}/share"
}

package_python2-nose() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools")

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})

  cd "${srcdir}/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${_mingw_prefix}/bin/|/usr/bin/env |g" -i ${_f}
  done
}

package_mingw-w64-i686-python2-nose() {
  package_python2-nose
}

package_mingw-w64-i686-python3-nose() {
  package_python3-nose
}

package_mingw-w64-x86_64-python2-nose() {
  package_python2-nose
}

package_mingw-w64-x86_64-python3-nose() {
  package_python3-nose
}
